package com.cwd.arm.application.service.read;

import com.cwd.arm.infrastructure.dao.ReceiveRecordDao;
import com.cwd.arm.infrastructure.po.ReceiveRecordPo;
import com.cwd.arm.application.dto.ReceiveRecordDto;
import com.cwd.arm.application.service.read.facade.ReceiveRecordReadService;
import com.cwd.arm.infrastructure.query.ReceiveRecordDaoQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Description:收款记录
* Created on 2021年11月16日
* @author  yan
*/
@Repository
@Primary
public class ReceiveRecordReadServiceImpl implements ReceiveRecordReadService {

    @Autowired
    private ReceiveRecordDao receiveRecordDao;

    @Override
    public ReceiveRecordDto selectById(Long id) {
        // TODO: 21-11-15
        return convertToDto(null);
    }

    @Override
    public List<ReceiveRecordDto> selectByProjectId(Long projectId) {
        ReceiveRecordDaoQuery daoQuery = new ReceiveRecordDaoQuery();
        daoQuery.setProjectId(projectId);
        return selectByQuery(daoQuery);
    }

    @Override
    public List<ReceiveRecordDto> selectByQuery(ReceiveRecordDaoQuery daoQuery) {
        List<ReceiveRecordPo> poList = receiveRecordDao.selectByQuery(daoQuery);
        return convertToDtoList(poList);
    }

    private ReceiveRecordDto convertToDto(ReceiveRecordPo po){
        ReceiveRecordDto dto = new ReceiveRecordDto();
        BeanUtils.copyProperties(po, dto);
        return dto;
    }

    private List<ReceiveRecordDto> convertToDtoList(List<ReceiveRecordPo> poList){
        return poList.stream().map(po->convertToDto(po)).collect(Collectors.toList());
    }

}
